package dev.ece.suit.hexmap;

import java.util.ArrayList;
import java.util.List;

import dev.ece.core.vertex.VAO;
import dev.ece.core.vertex.VBO;
import dev.ece.util.lib.Vector2f;
import dev.ece.util.lib.Vector3f;

@Deprecated
public class HexMapWaterCellVAO {

	private VBO verticeVBO;
	
	private VBO uvVBO;
	
	private VAO vao;
	
	public static HexMapWaterCellVAO createHexMapWaterCellVAO(List<HexMapWaterCell> waters) {
		List<Vector3f> vertice = new ArrayList<Vector3f>();
		List<Vector2f> uv = new ArrayList<Vector2f>();
		int index = 0;
		for(HexMapWaterCell cell:waters) {
			vertice.addAll(cell.getVertice());
			uv.addAll(cell.getUv());
			cell.setup();
			cell.setFirst(index * cell.getVertice().size());
			index ++;
		}
		HexMapWaterCellVAO vao = new HexMapWaterCellVAO();
		vao.verticeVBO = VBO.newInstance3f(vertice);
		vao.uvVBO = VBO.newInstance2f(uv);
		
		vertice.clear();
		uv.clear();
		vertice = null;
		uv = null;
		return vao;
	}
	
	public void initialize() {
		vao = new VAO();
		vao.bind();
		vao.bindVertexArrayBuffer(verticeVBO, 3);
		vao.bindVertexArrayBuffer(uvVBO, 2);
		vao.finish();
		
		verticeVBO = null;
		uvVBO = null;
	}
	
	public void destroy() {
		if(vao != null) {
			vao.destroy();
		}
	}
	
	public void bind() {
		vao.bind();
	}

	public VAO getVao() {
		return vao;
	}
	
}
